package org.springtest.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

public class Account extends User implements UserDetails {
	private Integer id;
	/*private String username;
	private String password;
	private List<AccountRole> accountRoles;*/
	
	/*public Account() {
		super("NONE", "NONE", false, false,false, false, new ArrayList<GrantedAuthority>());
	}*/
	
	public Account(String username, String password, boolean enabled, boolean accountNonExpired,
            boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities) {
		super(username, password, enabled, accountNonExpired,
	            credentialsNonExpired, accountNonLocked, authorities);
	}
	
	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}
	
	/*public void setPassword(String password) {
      this.password = password;
    }

    public void setUsername(String username) {
        this.username = username;
    }*/

	public void addAccountRole(AccountRole arole) {
		this.getAuthorities().add(arole);		
	}
	
/*	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
		
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String userName) {
		this.username = userName;
	}
		
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void addAccountRole(AccountRole ar) {
		accountRoles.add(ar);
	}
	
	public boolean isEnabled() {
		return true;		
	}

	public Collection<GrantedAuthority> getAuthorities() {
		Set ga = new HashSet();
		
		for (AccountRole ar : this.accountRoles) {
			ga.add(new GrantedAuthorityImpl(ar.getRole()));
		}
		
		return ga;
	}

	public boolean isAccountNonExpired() {
		return true;
	}

	public boolean isAccountNonLocked() {
		return true;
	}

	public boolean isCredentialsNonExpired() {
		return true;
	}

	ReflectionSaltSource
*/
}
